package controller

import (
	"github.com/gin-gonic/gin"
	"github.com/mojocn/base64Captcha"
	"net/http"
)

var store = base64Captcha.DefaultMemStore

// 图形验证码
func Captcha(c *gin.Context) {
	digit := base64Captcha.NewDriverDigit(80, 240, 5, 0.7, 80)
	captcha := base64Captcha.NewCaptcha(digit, store)
	captchaId, Base64Url, _, err := captcha.Generate()
	if err != nil {
		ReturnErrorJson(err, c)
		return
	}
	c.JSON(http.StatusOK, gin.H{
		"cade": 0,
		"Data": map[string]interface{}{
			"captcha_id": captchaId,
			"url":        Base64Url,
		},
		"msg": "success",
	})
	return
}
